package khiem.demo.jscompress;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

import khiem.demo.jscompress.libs.ClosureCompiler;
import khiem.demo.jscompress.libs.JSMin;

/**
 * This class tests some techniques and libraries about javascript compression.
 * <p>
 * We have some techniques: <br/>
 * &nbsp;&nbsp;- JSMin: http://www.crockford.com/javascript/jsmin.html <br/>
 * &nbsp;&nbsp;- Google Closure Compiler <br/>
 * &nbsp;&nbsp;- YUI Compressor <br/>
 *
 *
 * &bull; <b>JSMIN</b>
 * &nbsp;&nbsp;- JSMin is a filter that omits or modifies some characters.It does not change the behavior of the 
 * program.<br/>
 * &nbsp;&nbsp;- JSMin replaces carriage returns ('\r') with linefeeds ('\n')<br/>
 * &nbsp;&nbsp;- Replaces all control characters (including tab) with spaces.<br/>
 * &nbsp;&nbsp;- Replaces comments in /* *\/ form with spaces.<br/>
 * &nbsp;&nbsp;- All runs of spaces are replaced with a single space. <br/>
 * &nbsp;&nbsp;&nbsp;&nbsp;All runs of linefeeds are replaced with a single linefeed.<br/>
 * ...
 */
public class JSCompressDemo  {
    
  public static void main(String args[]) throws IOException {
    File jsFile = new File("src/main/resources/UICalendarPortlet.js");
    File outputFile = new File("src/main/resources/JSMin-output.js");
    Reader input = new FileReader(jsFile);
    Writer output = new FileWriter(outputFile);
    JSMin.getInstance().compress(input, output);
    input.close();
    output.close();
    input = new FileReader(jsFile);
    output = new FileWriter(new File("src/main/resources/Closure-output-whitespace.js"));
    ClosureCompiler.getInstance().compress(input, output);
    input.close();
    output.close();
  }
}
